package com.softstao.guoyu.ui.activity.agent;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.softstao.guoyu.R;
import com.softstao.guoyu.base.BaseActivity;
import com.softstao.guoyu.model.agent.SubInfo;
import com.softstao.guoyu.model.agent.TeamCount;
import com.softstao.guoyu.mvp.interactor.agent.AgentInteractor;
import com.softstao.guoyu.mvp.presenter.agent.AgentPresenter;
import com.softstao.guoyu.mvp.viewer.agent.TeamCountViewer;
import com.softstao.softstaolibrary.library.utils.LZUtils;
import com.softstao.softstaolibrary.library.widget.CustomScrollerView;
import com.wangjie.androidinject.annotation.annotations.mvp.AIPresenter;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by vaikus on 2017/7/26.
 */

public class OtherTeamActivity extends BaseActivity implements TeamCountViewer {

    @AIPresenter(presenter = AgentPresenter.class, interactor = AgentInteractor.class)
    AgentPresenter presenter;

    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.level)
    TextView level;
    @BindView(R.id.pick_time)
    TextView pickTime;
    @BindView(R.id.balance)
    TextView balance;
    @BindView(R.id.total_num)
    TextView totalNum;
    @BindView(R.id.direct_view)
    TextView directView;
    @BindView(R.id.recommend_from_me)
    TextView recommendFromMe;
    @BindView(R.id.recommend_to_me)
    TextView recommendToMe;
    @BindView(R.id.scroll_view)
    CustomScrollerView scrollView;
    private SubInfo subInfo;
    private int id;
    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    private String level_name,lateLy_date;
    private TeamCount teamCount;

    @Override
    public int _ContentView() {
        return R.layout.activity_other_team;
    }

    @Override
    public void initView() {
        initTitle("TA的团队");
        subInfo = (SubInfo) getIntent().getSerializableExtra("subInfo");
        id = getIntent().getIntExtra("id",0);

        name.setText(subInfo.getName());
        switch (subInfo.getLevel()){
            case 1:
                level_name = "天使";
                break;
            case 2:
                level_name = "皇冠";
                break;
            case 3:
                level_name = "一级";
                break;
            case 4:
                level_name = "市代";
                break;
            case 5:
                level_name = "省代";
                break;
            case 6:
                level_name = "总部";
                break;
            case 7:
                level_name = "未授权";
                break;
        }
        level.setText(level_name);
        lateLy_date = subInfo.getLatelyOrderDate()==0?"——":format.format(new Date(subInfo.getLatelyOrderDate()));
        pickTime.setText("最近提货："+lateLy_date);
        balance.setText("虚拟币："+ LZUtils.priceFormat(subInfo.getVirtualCurrency()) + "元");
    }

    private void initData() {
        totalNum.setText("TA的团队人数：" + (teamCount.getDirectSubCount()+teamCount.getMeRecommendCount()+teamCount.getRecommendToMeCount()) + "人");
        directView.setText("直属代理：" + teamCount.getDirectSubCount() + "人");
        recommendFromMe.setText("我的转推荐代理：" + teamCount.getMeRecommendCount() + "人");
        recommendToMe.setText("转荐给我的代理：" + teamCount.getRecommendToMeCount() + "人");
    }

    @OnClick({R.id.direct_view, R.id.recommend_from_me, R.id.recommend_to_me})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.direct_view:
                Intent directIntent = new Intent(context, AgentListActivity.class);
                directIntent.putExtra("type","direct");
                directIntent.putExtra("id",id);
                startActivity(directIntent);
                break;
            case R.id.recommend_from_me:
                Intent fromIntent = new Intent(context,AgentListActivity.class);
                fromIntent.putExtra("type","from");
                fromIntent.putExtra("id",id);
                startActivity(fromIntent);
                break;
            case R.id.recommend_to_me:
                Intent toIntent = new Intent(context,AgentListActivity.class);
                toIntent.putExtra("type","to");
                toIntent.putExtra("id",id);
                startActivity(toIntent);
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        getTeamCount();
    }

    @Override
    public void getTeamCount() {
        presenter.getTeamCount(id);
    }

    @Override
    public void getResult(TeamCount teamCount) {
        if (teamCount!=null){
            this.teamCount = teamCount;
            initData();
        }
    }
}
